/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package aicue1.beans;

import java.math.BigDecimal;
import javax.xml.bind.Unmarshaller;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author Tom
 */
@XmlRootElement(name = "Item")
public class Item {
    private String product_id;
    private int quantity;
    private BigDecimal single_unit_price;
    private Order order;

    public Item()
    {
    }

    public Item(String product_id, int quantity, BigDecimal single_unit_price, Order order)
    {
        this.product_id = product_id;
        this.quantity = quantity;
        this.single_unit_price = single_unit_price;
        this.order = order;
    }

    @XmlAttribute
    public String getProduct_id() {
        return product_id;
    }

    public void setProduct_id(String product_id) {
        this.product_id = product_id;
    }

    //@XmlElement
    @XmlTransient
    public Order getOrder() {
        return order;
    }

    public void setOrder(Order order) {
        this.order = order;
    }

    @XmlElement
    public int getQuantity() {
        return quantity;
    }

    public void setQuantity(int quantity) {
        this.quantity = quantity;
    }

    @XmlElement
    public BigDecimal getSingle_unit_price() {
        return single_unit_price;
    }

    public void setSingle_unit_price(BigDecimal single_unit_price) {
        this.single_unit_price = single_unit_price;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final Item other = (Item) obj;
        if ((this.product_id == null) ? (other.product_id != null) : !this.product_id.equals(other.product_id)) {
            return false;
        }
        if (this.order != other.order && (this.order == null || !this.order.equals(other.order))) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        int hash = 7;
        hash = 97 * hash + (this.product_id != null ? this.product_id.hashCode() : 0);
        hash = 97 * hash + (this.order != null ? this.order.hashCode() : 0);
        return hash;
    }

    public void afterUnmarshal(Unmarshaller u, Object parent)
    {
        if (parent instanceof Order) this.order = (Order) parent;
        else this.order = null;
    }
}